import { useUserStore} from "../store/user";
import constants from "../utils/constants";
const userStore = useUserStore()
const header = {
    'Content-Type': 'application/json',
    'authentication': userStore.getUserToken
  }
// 上传文件
export function uploadFile(tempFilePath) {
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      // 修改为后端接口的正确路径
      url: constants.database + '/user/common/upload', 
      filePath: tempFilePath,
      // 修改为后端接收的文件参数名
      name: 'file', 
      formData: {
        'type': 'medicine'
      },
      header: {
        'Content-Type': 'application/json',
        'authentication': userStore.getUserToken
      },
      success: (uploadRes) => {
        resolve(uploadRes.data);
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
}